//
//  BKResultOfZhuanYeViewController.m
//  baokaodaxue
//
//  Created by dangyangyang on 15/6/6.
//  Copyright (c) 2015年 宏图教育. All rights reserved.
//

#import "BKResultOfZhuanYeViewController.h"
#import "BKMatchingScoreTableViewCell.h"
#import "BKBlackTextField.h"
#import <ReactiveCocoa.h>
#import <RACEXTScope.h>
#import "BKZhuanYeViewModel.h"
#import "BKZhuanYeTableViewCell.h"
#import "MJRefresh.h"

static NSString *ZhuanYeCell = @"MatchingScore";

@interface BKResultOfZhuanYeViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (weak, nonatomic) IBOutlet UITableView *tableView;
//@property (weak, nonatomic) IBOutlet BKBlackTextField *dq;
//@property (weak, nonatomic) IBOutlet BKBlackTextField *lx;
@end

@implementation BKResultOfZhuanYeViewController

- (IBAction)p_back:(id)sender {
    [self.navigationController popViewControllerAnimated:YES];
}

- (NSMutableArray *)dataArray
{
    if (_dataArray == nil) {
        _dataArray = [NSMutableArray array];
    }
    return _dataArray;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    _page = 1;
    // Do any additional setup after loading the view from its nib.
    [_tableView registerNib:[UINib nibWithNibName:NSStringFromClass([BKZhuanYeTableViewCell class]) bundle:nil] forCellReuseIdentifier:ZhuanYeCell];
    
    _tableView.separatorColor = [UIColor clearColor];
    
    
    // 添加动画图片的上拉刷新
    // 添加传统的上拉刷新
    __weak BKResultOfZhuanYeViewController *weakSelf = self;
    [self.tableView addLegendFooterWithRefreshingBlock:^{
        self.tableView.footer.hidden = NO;
        // 进入刷新状态后会自动调用这个block
        
        if (weakSelf.flag) {
            [BKZhuanYeViewModel colleageWithKaoqu:_zhuanye wenli:_wenli piciCode:_piciCode dalei:_dalei zhuanye:_zhuanye page:[NSString stringWithFormat:@"%d",weakSelf.page] success:^(NSArray *dataArray) {
                if (dataArray.count != 20) {
                    weakSelf.flag = false;
                }
                
                for (NSDictionary *dict in dataArray) {
                    [weakSelf.dataArray addObject:dict];
                }
                
                dispatch_async(dispatch_get_main_queue(), ^{
                    
                    [weakSelf.tableView reloadData];
                    self.tableView.footer.hidden = YES;
                });
                
                weakSelf.page ++;
            } failure:^(NSString *error) {
                self.tableView.footer.hidden = YES;
            }];
        } else {
            self.tableView.footer.hidden = YES;
        }
    }];
    
}


- (void)setDataDic:(NSDictionary *)dataDic{

    _dataDic = dataDic;
    
    NSMutableArray *dataArray = [NSMutableArray array];
    
    if ([dataDic isKindOfClass:[NSDictionary class]]) {
        NSArray *keys = [dataDic allKeys];
        for (id key in keys) {
            [dataArray addObject:dataDic[key]];
        }
        
        _dataArray = dataArray;
    }
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return [_dataArray count];
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    BKZhuanYeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ZhuanYeCell];
    
    NSDictionary *dic = _dataArray[indexPath.row];
    cell.h14Label.text = dic[@"h14"];
    cell.h13Label.text = dic[@"h13"];
    cell.h12Label.text = dic[@"h12"];
    
    cell.l14Label.text = dic[@"l14"];
    cell.l13Label.text = dic[@"l13"];
    cell.l12Label.text = dic[@"l12"];
    
    cell.a14Label.text = dic[@"a14"];
    cell.a13Label.text = dic[@"a13"];
    cell.a12Label.text = dic[@"a12"];
    
    cell.nameLabel.text = dic[@"name"];
    
    if (indexPath.row%2 == 0) {
        cell.backgroundColor = [UIColor clearColor];
    }else{
        cell.backgroundColor = [UIColor colorWithRed:0.922 green:0.965 blue:0.980 alpha:.5];
    }
    
    cell.selected = NO;
  
    return cell;
    
    
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{


    return 60;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{

    return [UIView new];
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{

    return 10;
}


@end
